home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1998 May / Macworld (1998-05).dmg / Shareware World / Comms & Internet / ImageMapper v3.0 / Goodies / Java / java / Source / HighlightableLink.java next >
Text File  |  1998-03-08  |  2KB  |  120 lines

  1. import java.awt.*;
  2. import java.net.URL;
  3. import java.applet.*;
  4.  
  5. /*
  6.  *
  7.  * HighlightableLink
  8.  *
  9.  */
  10.  
  11. public class HighlightableLink extends Canvas
  12. {
  13.  
  14.     public HighlightedImageMap     applet=null;
  15.      
  16.     Image normal;
  17.     Image highlighted;
  18.     String alt;
  19.     String target;
  20.  
  21.     URL url;
  22.     
  23.     AudioClip audio = null;
  24.  
  25.     boolean active=false;
  26.  
  27.     public HighlightableLink(int x, int y, 
  28.                    int width, int height, 
  29.                    Image normal, Image highlighted, 
  30.                    URL url, URL audioURL, String alt, String target, HighlightedImageMap applet)
  31.     {
  32.         reshape(x,y+50,width,height);
  33.         move(x,y);
  34.  
  35.         this.normal=normal;
  36.         this.highlighted=highlighted;
  37.         this.url=url;
  38.         this.alt=alt;
  39.         this.target=target;
  40.  
  41.         this.applet=applet;
  42.         
  43.         if (audioURL != null)
  44.         {
  45.             this.audio = applet.getAudioClip(audioURL);
  46.         }
  47.     }
  48.  
  49.     public void paint(Graphics g)
  50.     {
  51.         if (applet.nloaded && applet.hloaded)
  52.         {
  53.             if (active)
  54.                 g.drawImage(highlighted,0,0,this);
  55.             else
  56.                 g.drawImage(normal,0,0,this);
  57.         }
  58.         else
  59.         {
  60.             g.drawRect(0,0,size().width-1,size().height-1);
  61.             g.drawString(alt,2,(g.getFontMetrics().getHeight()>>1)+size().height/2);
  62.         }
  63.  
  64.     }
  65.  
  66.     public void update(Graphics g)
  67.     {
  68.         paint(g);
  69.     }
  70.  
  71.     public boolean mouseEnter(Event evt, int x, int y)
  72.     {
  73.         active=true;
  74.         
  75.         if (!alt.equals(""))
  76.         {
  77.             applet.showStatus(alt);
  78.         }
  79.         else
  80.         {
  81.             applet.showStatus(url.toString());
  82.         }
  83.         
  84.         repaint();
  85.        
  86.         return true;
  87.     }
  88.  
  89.     public boolean mouseExit(Event evt, int x, int y)
  90.     {
  91.  
  92.         active=false;
  93.         applet.showStatus("");
  94.         
  95.         repaint();
  96.  
  97.         return true;
  98.     }
  99.  
  100.     public boolean mouseDown(Event evt, int x, int y)
  101.     {
  102.         //Use framename if given, otherwise default frame is target
  103.         if (audio != null)
  104.         {
  105.             audio.play();
  106.         }
  107.  
  108.         if (!target.equals(""))
  109.         {
  110.             applet.getAppletContext().showDocument(url,target);
  111.         }
  112.         else
  113.         {
  114.             applet.getAppletContext().showDocument(url);
  115.         }
  116.           
  117.         return true;
  118.     }
  119.  
  120. }